<template>
  <div class="mobile-home">
    <van-tabs v-model="active" @click="menuClick">
      <van-tab :name="0" title="书写报告"></van-tab>
      <van-tab :name="1" title="已报告"></van-tab>
    </van-tabs>
    <div class="mobile-home-list scrollbar">
      <van-list v-model="loading" :finished="finished" :finished-text="listData.length > 0 ? '没有更多了' : ''"
        @load="initAjaxMethod">
        <div class="list-cell" v-for="(item, index) in listData" :key="index">
          <div class="list-card">
            <div class="list-header">
              <van-tag type="danger" v-if="item.urgencyDegree == '1'">急</van-tag>
              <span style="font-size: 16px">{{ item.inspectionArea }}</span>
            </div>
            <!-- @click="jump(item, 6)" -->
            <van-cell-group >
              <!-- 有些解析结果不一样 -->
              <!-- <van-field :border="false"
                :value="`${item.name || ''}${item.age > 0 ? '【' + item.age + '岁】' : ''}【${item.sex || '男'}】`" readonly /> -->
              
               <van-field :border="false" label="姓名" :value="item.name" readonly />
              <van-field :border="false" label="医院" :value="item.hospital" readonly />
              <van-field :border="false" label="检查号" :value="item.checkNo" readonly />
              <van-field :border="false" label="检查日期" :value="item.checkDate" readonly />
            </van-cell-group>
            <div class="list-footer">
              <!-- round item.status -->
                   <van-button type="info" size="small" round @click="jump(item, 6)" v-if="seltype==0">信息编辑</van-button>
              <van-button type="info" size="small" round @click="jump(item, 1)">影像查看</van-button>
         
              <van-button type="info" size="small" round @click="jump(item, 2)" v-if="seltype==0">写报告</van-button>
              <van-button type="info" size="small" round @click="funviewreport(item, 1)" v-if="seltype==1">报告信息</van-button>
              <van-button type="info" size="small" round @click="changereport(item, 1)"  v-if="item.status==1">召回</van-button>
              <van-button type="info" size="small" round @click="jump(item, 3)" v-if="item.status==3">分享</van-button>
              <!-- <van-button type="info" size="small" round @click="jump(item, 4)">复制</van-button> -->
              <!-- <van-button type="danger" size="small" round @click="jump(item, 5)">删除</van-button> -->
            </div>
          </div>
        </div>
      </van-list>
      <not-find v-if="listData.length == 0" />
    </div>
    <van-action-sheet v-model:show="show" cancel-text="取消" close-on-click-action title="分享">
      <div>
        <div class="qrcode-group">
          <img :src="shareObj.ewmurl" alt="">
        </div>
        <!-- <van-field v-model="mobile" type="tel" clearable center label="手机号码" placeholder="请输入手机号码">
          <template #button>
            <van-button size="small" type="primary">发送</van-button>
          </template>
        </van-field> 
        <van-button type="default" block  @click="shareMethod(2)">复制链接</van-button> -->
      </div>
    </van-action-sheet>

     <!-- v1 pdf 插件 -->
     <!-- <van-popup closeable v-model="dialogBg" position="bottom" :style="{ height: '100%' }">
            <iframe :src="pdfUrl" frameborder="0" style="width:100%;height:88%;margin-top:12%;"></iframe>
    </van-popup> -->

        <!-- <van-popup closeable v-model="dialogBg" position="bottom" :style="{ height: '100%',background:'#000'}">
            <img :src="pdfUrl" style="width:100%;height:88%;margin-top:12%;object-fit: contain;background:#fff;">
        </van-popup> -->


        <van-popup closeable v-model="dialogBg" position="bottom" :style="{ height: '100%',background:'#000'}">
            <img :src="pdfUrl" style="width:100%;height:88%;margin-top:12%;object-fit: contain;background:#fff;">
        </van-popup>

  </div>
</template>

<script>
// import {Toast, Dialog, Tab, Tabs, ActionSheet, Tag, Button, Field, List, CellGroup, Col, Row ,Popup , Icon,Overlay} from "vant";
import { Dialog, Tab, Tabs, ActionSheet, Tag, Button, Field, List, CellGroup,Popup,Toast } from "vant";
import notFind from "@/view/common/notFind";
import { getdate1 } from "@/utils/utils";
export default {
  name:'mobileHome',
  components: {
    notFind,
    [Dialog.Component.name]: Dialog.Component,
    [Tab.name]: Tab,
    [Tabs.name]: Tabs,
    [ActionSheet.name]: ActionSheet,
    [Tag.name]: Tag,
    [Button.name]: Button,
    [Field.name]: Field,
    [List.name]: List,
    [CellGroup.name]: CellGroup,
    [Popup.name]: Popup,
  },
  filters: {
    formDate: (val) => {
      console.log(val);
      return getdate1(val)
    }
  },
  data: function () {
    return {
      active: 0,
      mobile: '',
      listData: [],
      dialogBg:false,
      pdfUrl:'',
      loading: false,
      finished: true,
      isLoading: false,
      show: false,
      shareObj:{
        mobile:'',
        // shareurl:'https://lanyingsup.zrs360.vip/public/uploads/ewm/SF20230711162835885.png',
        // ewmurl:'https://lanyingsup.zrs360.vip/public/uploads/ewm/SF20230711162835885.png'
        shareurl:'',
        ewmurl:''

      },
      query: {          
        pageNum: 1,
        pageSize: 10,
        // status: 0
      },
      seltype:0
    };
  },
  mounted() {
    this.initAjaxMethod();
  },
  methods: {
    menuClick(name) {
         console.log('shuaxin2');
      this.query.status = name;
      this.seltype=name;
      if(name==1){
        // 已报告
       this.resultMethod()
      }else{
        this.resultMethod()
      }
     
    },
    onRefresh() {
          console.log('shuaxin1');
      this.isLoading = true;
      this.resultMethod()
    },
    resultMethod() {
       console.log('shuaxin3');
      this.query.pageNum = 1;
      this.listData = [];
      this.finished = false;
      this.loading = true;
      this.initAjaxMethod();
    },
    initAjaxMethod() {

      console.log("status",this.seltype);
      let url=this.$API.MIBILE_ADMIN_LISTv202;
      if(this.seltype==1){
        // 已报告
         url=this.$API.MIBILE_ADMIN_LISTokv2;
      }


      this.$http.get(url, this.query).then((res) => {
        console.log('res', res);
        if (res.code == 200) {
          let list = Array.isArray(res.rows) ? res.rows : [];
          let isOver = list.length < this.query.pageSize ? true : false;
          console.log("sdf",isOver,"pagen",this.query.pageNum,'total',res.total);
          this.finished = isOver;
          this.loading = false;
          this.isLoading = false;
          this.listData = [...this.listData, ...list];
          this.total = res.total;
          if (!isOver) {
            this.query.pageNum++;
          }
        } else {
          this.loading = false;
          this.finished = true;
          this.isLoading = false;
        }
      });
    },
    jump(data, flag) {
      if (flag == 1) {
          //         let expires=this.getQueryVariable('expires');
          // let signature=this.getQueryVariable('signature');
          // let serverAddr=this.getQueryVariable('serverAddr');

        this.$router.push({ path: '/mobile/admin/image', query: { id: data.id,expires: data.expires,
        signature: data.signature,serverAddr: data.serverAddr,hoscode:data.hospitalid
        } })
      } else if (flag == 2) {
         
        //  let para={ zid: data.id,token:data.token,nt:data.totime,checkno:data.checkno,hoscode:data.hospitalid };
        this.$router.push({ path: '/mobile/admin/write', query: { id: data.id,expires: data.expires,
         signature: data.signature,serverAddr: data.serverAddr,token:data.token,nt:data.totime,checkno:data.checkno,hoscode:data.hospitalid,checkdate:data.checkDate
         } })
      } else if (flag == 3) {
        //分享
        this.detailMethod(data);
        // this.show = true;
      } else if (flag == 4) {

      } else if (flag == 5) {
        Dialog.confirm({
          title: '提示',
          message: '是否继续此操作？',
        }).then(() => {
          // on confirm


        })
          .catch(() => { });
      }else if (flag == 6) {
        // 
        // let checkno=encodeURIComponent("蓝影LYSC_"+data.checkno);
        // id: data.id,expires: data.expires,
        //  signature: data.signature,serverAddr: data.serverAddr,token:data.token,nt:data.totime,checkno:data.checkno,hoscode:data.hospitalid
        this.$router.push({ path: '/mobile/admin/detail', query: { id: data.id,token:data.token,nt:data.totime,checkno:data.checkno,hoscode:data.hospitalid,checkdate:data.checkDate } })
      }
    },

     funviewreport(data1,flag) {
            console.log(111,data1);
            if(flag>=2){
                // this.reportDetail.zid=this.id;
                // this.reportDetail.buttons=item;
                // const loading = this.$loading({ text: '提交中' });
                // this.$http.post(this.$API.MOBILE_REPORT_TREE_EDIT, this.reportDetail)
                //     .then((res) => {
                //         loading.close();
                //         console.log('登录信息', res)
                //         if (res.code == 1) {
                //             Toast.success('操作成功');
                //             this.getDetail()
                //         }else{
                //             Toast.fail(res.msg);
                //         }
                //     })
            }else{
                // let url=this.$API.DOMAIN_NAME+this.$API.MOBILE_REPORT_VIEWREPORT+'?id='+item.id+'&.pdf';
                // this.pdfUrl= `${this.$API.DOMAIN_NAME}/web/pdf/web/viewer.html?file=${encodeURIComponent(url)}`;
                // this.dialogBg=true;
 
              //  let para={ zid: data1.id,token:data1.token,nt:data1.totime,checkno:data1.checkno,hoscode:data1.hospitalid,checkdate:data1.checkDate };
              //  MOBILE_REPORT_DETAIL   MOBILE_REPORT_viewreportossv2
              //  ,para     63
              // MOBILE_REPORT_viewreportossv202  

              //let url=this.$API.MOBILE_REPORT_viewreportossv202+"/"+data1.id

                 //let url=this.$API.MOBILE_REPORT_viewreportossv202+"/"+zid
              let url=this.$API.QUERY_CHECK_SEARCHv2
 
              let para={ zid: data1.id,hospitalId:data1.hospitalId,checkNo:data1.checkNo,checkdate:data1.checkDate }


               this.$http
                .get(url,para )
                .then((res) => {
                if (res.code == 200) {
                    console.log('res',res);
                    // this.pdfUrl=res.data;
                    this.dialogBg=true;

                     //this.pdfUrl=res.data;
                   this.pdfUrl=res.data.reportUrl;


                } else {
                    Toast.fail(res.msg);
                }
                });




            }
        },

          changereport(item,flag) {
            console.log(111,item);
                let hoscode=item.hospitalid;
                let checkno=item.checkno;
                let checkdate=item.checkDate;
                let para={zid:item.id,status:flag,hoscode:hoscode,checkno:checkno,checkdate:checkdate};

                // let para={zid:item.id,status:1};
                const loading = this.$loading({ text: '提交中' });
                this.$http.get(this.$API.MOBILE_REPORT_TREE_CHANGEstv2+"/"+item.id, para)
                    .then((res) => {
                        loading.close();
                        console.log('登录信息', res)
                        if (res.code == 200) {
                            Toast.success('操作成功');
                            // this.getDetail()                         
                             this.query.status = 0;
                             this.active=0;
                                this.resultMethod()
                            //  this.initAjaxMethod();
                        }else{
                            Toast.fail(res.msg);
                        }
                    })
            
        },



        


         //分享详情加载
    detailMethod(data1) {
      this.$http
        .post(this.$API.MOBILE_REPORT_SHAREREPORT, {
           zid: data1.id,hoscode:data1.hospitalid,checkno:data1.checkno,checkdate:data1.checkDate
        })
        .then((res) => {
          console.log("媒资列表", res);
          if (res.code == 1) {

        
        this.shareObj = {
          shareurl: res.data.shareurl,
          ewmurl:res.data.shareewmurl,
           
        }   
        this.show = true; 
        // this.dialogshare = true;
        // this.id = id;
        // this.dialogsharetitle = "分享"; 
            // this.tableData = Array.isArray(res.data.list) ? res.data.list : [];
            // this.pageTotal = res.data.total;
          }
        });
    },
    shareMethod(flag){
      if(flag == 1){
        if(!(/^1[123456789]\d{9}$/.test(this.shareObj.mobile))){ 
            return this.$message.error('手机号码格式有误');
        } 

        // 发送代码
      }else if(flag == 2){
        this.$copyText(this.shareObj.shareurl).then(
	      e=>{
          this.$message.success('复制成功');
	      },
	      e=>{
          this.$message.error('复制失败');
	      }
      )
      }else if(flag == 3){
        this.$http.downMetod(this.shareObj.ewmurl,'二维码_'+Date.now())
      }else if(flag == 4){
        this.printNewWindow();
      }
    },

  },
};
</script>
<style lang="less" scoped>
.mobile-home {
  height: 100%;

  .mobile-home-list {
    height: calc(100vh - 98px)
  }

  .list-cell {
    padding: 0 16px;
  }

  .list-card {
    background: #FFFFFF;
    box-shadow: 0px 2px 20px 0px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    padding: 10px;
    margin-top: 16px;
  }

  .list-header {
    padding: 8px 0;
    display: flex;
    align-items: center;
  }

  .list-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
  }
  .qrcode-group{
    padding:10px;
    display: flex;
    align-items: center;
    justify-content: center;
    img{
      width: 200px;
      height: 200px;
    }
  }
}
</style>
<style>
.mobile-home .list-footer .van-button {
  width: 70px;
}
</style>
